/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.vcs.advanced; import java.io.*; import java.util.*; import java.beans.*; import java.text.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import java.text.*; import org.openide.*; import org.openide.util.*; import org.openide.filesystems.*; import org.netbeans.modules.vcs.util.*; import org.netbeans.modules.vcs.cmdline.*; import org.netbeans.modules.vcs.cmdline.exec.*; import org.netbeans.modules.vcs.*; /** Customizer * * @author Michal Fadljevic */ public class VcsCustomizer extends javax.swing.JPanel implements Customizer { private Debug E=new Debug("VcsCustomizer", true); // NOI18N private Debug D = E; static final long serialVersionUID =-8801742771957370172L; /** Creates new form VcsCustomizer */ public VcsCustomizer() { changeSupport=new PropertyChangeSupport(this); initComponents (); removeEnterFromKeymap(); saveAsButton.setMnemonic(KeyEvent.VK_S); removeConfigButton.setMnemonic(KeyEvent.VK_R); advancedButton.setMnemonic(KeyEvent.VK_A); browseButton.setMnemonic(KeyEvent.VK_B); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents advancedButton = new javax.swing.JButton (); propsPanel = new javax.swing.JPanel (); jLabel2 = new javax.swing.JLabel (); rootDirTextField = new javax.swing.JTextField (); browseButton = new javax.swing.JButton (); jLabel4 = new javax.swing.JLabel (); refreshTextField = new javax.swing.JTextField (); vcsPanel = new javax.swing.JPanel (); configCombo = new javax.swing.JComboBox (); saveAsButton = new javax.swing.JButton (); removeConfigButton = new javax.swing.JButton (); setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; advancedButton.setText (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.advancedButton.text")); advancedButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { advancedButtonActionPerformed (evt); } } ); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = 2; gridBagConstraints1.insets = new java.awt.Insets (0, 8, 8, 4); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; add (advancedButton, gridBagConstraints1); propsPanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints2; jLabel2.setText (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.jLabel2.text")); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 0; gridBagConstraints2.gridy = 2; gridBagConstraints2.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST; propsPanel.add (jLabel2, gridBagConstraints2); rootDirTextField.setColumns (15); rootDirTextField.setText ("."); rootDirTextField.setNextFocusableComponent (browseButton); rootDirTextField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { rootDirTextFieldActionPerformed (evt); } } ); rootDirTextField.addFocusListener (new java.awt.event.FocusAdapter () { public void focusLost (java.awt.event.FocusEvent evt) { rootDirTextFieldFocusLost (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 1; gridBagConstraints2.gridy = 2; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints2.weightx = 0.8; propsPanel.add (rootDirTextField, gridBagConstraints2); browseButton.setText (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.browseButton.text")); browseButton.setNextFocusableComponent (refreshTextField); browseButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { browseButtonActionPerformed (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 2; gridBagConstraints2.gridy = 2; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (4, 4, 4, 4); propsPanel.add (browseButton, gridBagConstraints2); jLabel4.setText (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.jLabel4.text")); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 0; gridBagConstraints2.gridy = 3; gridBagConstraints2.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST; propsPanel.add (jLabel4, gridBagConstraints2); refreshTextField.setText ("0"); refreshTextField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { refreshTextFieldActionPerformed (evt); } } ); refreshTextField.addFocusListener (new java.awt.event.FocusAdapter () { public void focusLost (java.awt.event.FocusEvent evt) { refreshTextFieldFocusLost (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 1; gridBagConstraints2.gridy = 3; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST; propsPanel.add (refreshTextField, gridBagConstraints2); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = 1; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (0, 8, 8, 8); gridBagConstraints1.weightx = 1.0; add (propsPanel, gridBagConstraints1); vcsPanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints3; configCombo.setNextFocusableComponent (saveAsButton); configCombo.addItemListener (new java.awt.event.ItemListener () { public void itemStateChanged (java.awt.event.ItemEvent evt) { configComboItemStateChanged (evt); } } ); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints3.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints3.weightx = 0.8; vcsPanel.add (configCombo, gridBagConstraints3); saveAsButton.setText (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.saveAsButton.text")); saveAsButton.setNextFocusableComponent (removeConfigButton); saveAsButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { saveAsButtonActionPerformed (evt); } } ); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints3.insets = new java.awt.Insets (4, 4, 4, 4); vcsPanel.add (saveAsButton, gridBagConstraints3); removeConfigButton.setText (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.removeConfigButton.text")); removeConfigButton.setNextFocusableComponent (propsPanel); removeConfigButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { removeConfigButtonActionPerformed (evt); } } ); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.gridx = 2; gridBagConstraints3.gridy = 0; gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints3.insets = new java.awt.Insets (4, 4, 4, 4); vcsPanel.add (removeConfigButton, gridBagConstraints3); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (8, 8, 0, 8); gridBagConstraints1.weightx = 1.0; add (vcsPanel, gridBagConstraints1); }//GEN-END:initComponents private void advancedButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed // Add your handling code here: advancedConfiguration (); }//GEN-LAST:event_advancedButtonActionPerformed private void refreshTextFieldFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_refreshTextFieldFocusLost // Add your handling code here: refreshChanged (); }//GEN-LAST:event_refreshTextFieldFocusLost private void rootDirTextFieldFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_rootDirTextFieldFocusLost // Add your handling code here: rootDirChanged (); }//GEN-LAST:event_rootDirTextFieldFocusLost private void refreshTextFieldActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshTextFieldActionPerformed // Add your handling code here: refreshChanged (); }//GEN-LAST:event_refreshTextFieldActionPerformed private void browseButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed // Add your handling code here: ChooseDirDialog chooseDir=new ChooseDirDialog(new JFrame(), new File(rootDirTextField.getText ())); MiscStuff.centerWindow (chooseDir); chooseDir.show(); String selected=chooseDir.getSelectedDir(); if( selected==null ){ //D.deb("no directory selected"); // NOI18N return ; } rootDirTextField.setText(selected); rootDirChanged(); /* String module = getModuleValue(); String moduleDir = module.equals ("") ? selected : selected + java.io.File.separator + module; // NOI18N File dir=new File(moduleDir); if( !dir.isDirectory() ){ E.err("not directory "+dir); return ; } try{ rootDirTextField.setText(selected); fileSystem.setRootDirectory(dir); } catch (PropertyVetoException veto){ fileSystem.debug("I can not change the working directory"); //E.err(veto,"setRootDirectory() failed"); } catch (IOException e){ E.err(e,"setRootDirectory() failed"); } */ }//GEN-LAST:event_browseButtonActionPerformed private void rootDirTextFieldActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rootDirTextFieldActionPerformed // Add your handling code here: rootDirChanged (); }//GEN-LAST:event_rootDirTextFieldActionPerformed private void removeConfigButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeConfigButtonActionPerformed // Add your handling code here: String label = (String) configCombo.getSelectedItem (); NotifyDescriptor.Confirmation nd = new NotifyDescriptor.Confirmation ("Are you sure you want to delete configuration: " + label, NotifyDescriptor.Confirmation.OK_CANCEL_OPTION); if(NotifyDescriptor.Confirmation.CANCEL_OPTION.equals (TopManager.getDefault ().notify (nd))) return; FileObject file = fileSystem.getConfigRootFO(); if (file != null) file = file.getFileObject((String) configNamesByLabel.get (label)); if (file != null) { try { file.delete(file.lock()); } catch (IOException e) { return; } promptForConfigComboChange = false; if(configCombo.getSelectedIndex() == 0) if (configCombo.getModel().getSize() > 1) configCombo.setSelectedIndex(1); else configCombo.setSelectedIndex(0); promptForConfigComboChange = false; updateConfigurations (); } /* File f = new File (fileSystem.getConfigRoot()+File.separator + configNamesByLabel.get (label) + ".properties"); // NOI18N if(f.isFile () && f.canWrite ()) { f.delete (); // set config to fileSystem, it will be rereaded after refresh in updateConfigurations () promptForConfigComboChange = false; if(configCombo.getSelectedIndex ()==0) configCombo.setSelectedIndex (1); else configCombo.setSelectedIndex (0); promptForConfigComboChange = false; updateConfigurations (); } */ }//GEN-LAST:event_removeConfigButtonActionPerformed private void saveAsButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsButtonActionPerformed // Add your handling code here: FileObject dir = fileSystem.getConfigRootFO(); ChooseFileObjectDialog chooseFile = new ChooseFileObjectDialog(new JFrame(), true, dir); MiscStuff.centerWindow (chooseFile); chooseFile.show(); String selected=chooseFile.getSelectedFile (); if (selected == null) return; FileObject file = dir.getFileObject(selected, "properties"); if (file == null) { try { file = dir.createData(selected, "properties"); } catch(IOException e) { E.err("Can not create file '"+selected+"'"); return; } } Vector variables=fileSystem.getVariables (); Object advanced=fileSystem.getAdvancedConfig (); String label = selected; VcsConfigVariable.writeConfiguration (file, label, variables, advanced, fileSystem.getVcsFactory ().getVcsAdvancedCustomizer ()); promptForConfigComboChange = false; fileSystem.setConfig (label); updateConfigurations (); /* ChooseFileDialog chooseFile=new ChooseFileDialog(new JFrame(), new File(fileSystem.getConfigRoot()), true); MiscStuff.centerWindow (chooseFile); chooseFile.show(); String selected=chooseFile.getSelectedFile (); if(selected==null) return; if(!selected.endsWith(".properties")) { // NOI18N selected += ".properties"; // NOI18N } File f = new File (selected); if( selected==null ){ //D.deb("no directory selected"); // NOI18N return ; } String label = selected; label = f.getName ().substring (0, f.getName ().length() - ".properties".length()); // NOI18N Vector variables=fileSystem.getVariables (); Object advanced=fileSystem.getAdvancedConfig (); VcsConfigVariable.writeConfiguration (selected, label, variables, advanced, fileSystem.getVcsFactory ().getVcsAdvancedCustomizer ()); promptForConfigComboChange = false; fileSystem.setConfig (label); updateConfigurations (); */ }//GEN-LAST:event_saveAsButtonActionPerformed private void configComboItemStateChanged (java.awt.event.ItemEvent evt) {//GEN-FIRST:event_configComboItemStateChanged // Add your handling code here: switch( evt.getStateChange() ){ case ItemEvent.SELECTED: String selectedLabel=(String)evt.getItem(); E.deb ("config state changed to:"+selectedLabel); if(selectedLabel.equalsIgnoreCase("empty")) { // NOI18N removeConfigButton.setEnabled (false); saveAsButton.setNextFocusableComponent (propsPanel); } else { removeConfigButton.setEnabled (true); saveAsButton.setNextFocusableComponent (removeConfigButton); } int selectedIndex=configCombo.getSelectedIndex(); if( oldIndex==selectedIndex ){ //D.deb("nothing has changed oldIndex==selectedIndex=="+oldIndex); // NOI18N return ; } String msg=g("MSG_Do_you_really_want_to_discard_current_commands",selectedLabel); // NOI18N NotifyDescriptor nd = new NotifyDescriptor.Confirmation (msg, NotifyDescriptor.YES_NO_OPTION ); if (!promptForConfigComboChange || TopManager.getDefault().notify( nd ).equals( NotifyDescriptor.YES_OPTION ) ) { //D.deb("yes"); // NOI18N // just do not display prompt for the first change if config was not edited promptForConfigComboChange = true; loadConfig(selectedLabel); oldIndex=selectedIndex; } else{ //D.deb("no"); // NOI18N String oldLabel=(String)configCombo.getItemAt(oldIndex); //D.deb("oldLabel="+oldLabel+", oldIndex="+oldIndex); // NOI18N loadConfig(oldLabel); configCombo.setSelectedIndex(oldIndex); } break ; case ItemEvent.DESELECTED: break ; } }//GEN-LAST:event_configComboItemStateChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton advancedButton; private javax.swing.JPanel propsPanel; private javax.swing.JLabel jLabel2; private javax.swing.JTextField rootDirTextField; private javax.swing.JButton browseButton; private javax.swing.JLabel jLabel4; private javax.swing.JTextField refreshTextField; private javax.swing.JPanel vcsPanel; private javax.swing.JComboBox configCombo; private javax.swing.JButton saveAsButton; private javax.swing.JButton removeConfigButton; // End of variables declaration//GEN-END:variables private static final double ADVANCED_DLG_WIDTH_RELATIVE = 0.9; private static final double ADVANCED_DLG_HEIGHT_RELATIVE = 0.6; /** * @associates JLabel */ private Vector varLabels = new Vector (); /** * @associates JTextField */ private Vector varTextFields = new Vector (); /** * @associates JButton */ private Vector varButtons = new Vector(); private Vector varVariables = new Vector (); private VcsFileSystem fileSystem=null; private PropertyChangeSupport changeSupport=null; /** * @associates String */ private Vector configLabels; private int oldIndex=0; private boolean promptForConfigComboChange = false; // Entries in hashtables are maintained as a cache of properties read from disk // and are read only. Changes are applied only to fileSystem.variables (fileSystem.commands). /** * @associates Vector */ private Hashtable configVariablesByLabel; /** * @associates Object */ private Hashtable configAdvancedByLabel; /** * @associates String */ private Hashtable configNamesByLabel; private boolean isRootNotSetDlg = true; //------------------------------------------- private void loadConfig(String label){ if(!label.equals (fileSystem.getConfig ())) { Vector variables=(Vector)configVariablesByLabel.get(label); Vector advanced=(Vector)configAdvancedByLabel.get(label); fileSystem.setVariables(variables); fileSystem.setAdvancedConfig(advanced); fileSystem.setConfig(label); } initAdditionalComponents (); } //------------------------------------------- public static void main(java.lang.String[] args) { JDialog dialog=new JDialog(new Frame (), true ); VcsCustomizer customizer= new VcsCustomizer(); dialog.getContentPane().add(customizer); dialog.pack (); dialog.show(); } //------------------------------------------- public void addPropertyChangeListener(PropertyChangeListener l) { //D.deb("addPropertyChangeListener()"); // NOI18N changeSupport.addPropertyChangeListener(l); } //------------------------------------------- public void removePropertyChangeListener(PropertyChangeListener l) { //D.deb("removePropertyChangeListener()"); // NOI18N changeSupport.removePropertyChangeListener(l); } private void removeEnterFromKeymap() { MiscStuff.removeEnterFromKeymap(rootDirTextField); MiscStuff.removeEnterFromKeymap(refreshTextField); } //------------------------------------------- private void advancedConfiguration () { JPanel panel = new JPanel (); panel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = 0; gridBagConstraints1.insets = new java.awt.Insets (8, 8, 0, 8); gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.weightx = 1; gridBagConstraints1.weighty = 0.5; final UserVariablesEditor variableEditor= new UserVariablesEditor(); variableEditor.setValue( fileSystem.getVariables() ); UserVariablesPanel variablePanel = new UserVariablesPanel (variableEditor); panel.add (variablePanel, gridBagConstraints1); PropertyEditor advancedEditor = fileSystem.getVcsFactory ().getVcsAdvancedCustomizer ().getEditor (fileSystem); JPanel advancedPanel = fileSystem.getVcsFactory ().getVcsAdvancedCustomizer ().getPanel (advancedEditor); gridBagConstraints1.gridy = 1; panel.add (advancedPanel, gridBagConstraints1); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); screenSize.setSize((int) (screenSize.width*ADVANCED_DLG_WIDTH_RELATIVE), variablePanel.getPreferredSize().height+advancedPanel.getPreferredSize().height+16); panel.setPreferredSize(screenSize); DialogDescriptor dd = new DialogDescriptor (panel, "Advanced Properties Editor"); TopManager.getDefault ().createDialog (dd).show (); if(dd.getValue ().equals (DialogDescriptor.OK_OPTION)) { fileSystem.setVariables ( (Vector)variableEditor.getValue ()); fileSystem.setAdvancedConfig (advancedEditor.getValue ()); } initAdditionalComponents (); } private void initAdditionalComponents () { refreshTextField.setVisible (true); jLabel4.setVisible (true); if(!fileSystem.getCache ().isLocalFilesAdd ()) { refreshTextField.setVisible (false); jLabel4.setVisible (false); } varVariables = new Vector (); while(varLabels.size ()>0) { propsPanel.remove ((JComponent) varLabels.get (0)); propsPanel.remove ((JComponent) varTextFields.get (0)); JComponent button = (JComponent) varButtons.get(0); if (button != null) propsPanel.remove (button); varLabels.remove (0); varTextFields.remove (0); varButtons.remove(0); } Enumeration vars = fileSystem.getVariables ().elements (); while (vars.hasMoreElements ()) { VcsConfigVariable var = (VcsConfigVariable) vars.nextElement (); if(var.isBasic ()) { JLabel lb; JTextField tf; JButton button = null; lb = new JLabel (); tf = new JTextField (); varLabels.add (lb); varTextFields.add (tf); java.awt.GridBagConstraints gridBagConstraints1; gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = varLabels.size () + 4; gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints1.weightx = 0; propsPanel.add (lb, gridBagConstraints1); tf.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { variableChanged (evt); } } ); tf.addFocusListener (new java.awt.event.FocusAdapter () { public void focusLost (java.awt.event.FocusEvent evt) { variableChanged (evt); } } ); gridBagConstraints1.gridx = 1; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.weightx = 1; propsPanel.add (tf, gridBagConstraints1); varVariables.add (var); String varLabel = var.getLabel ().trim (); if(!varLabel.endsWith (":")) varLabel += ":"; // NOI18N lb.setText (varLabel); tf.setText (var.getValue ()); if (var.isLocalFile ()) { button = new JButton (); button.addActionListener (new BrowseLocalFile (tf)); button.setText ("Browse..."); } else if (var.isLocalDir ()) { button = new JButton (); button.addActionListener (new BrowseLocalDir (tf)); button.setText ("Browse..."); } String selector = var.getCustomSelector(); if (selector != null && selector.length() > 0) { button = new JButton (); button.addActionListener (new RunCustomSelector (tf, var)); button.setText ("Select..."); } if (button != null) { gridBagConstraints1.gridx = 2; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.weightx = 0; propsPanel.add (button, gridBagConstraints1); } varButtons.add (button); MiscStuff.removeEnterFromKeymap(tf); } } java.awt.Component comp = this; while (comp!=null && !(comp instanceof java.awt.Window)) comp = comp.getParent (); if(comp!=null) { ((java.awt.Window) comp).pack (); } } private void variableChanged (java.awt.AWTEvent evt) { JTextField tf = (JTextField) evt.getSource (); VcsConfigVariable var=null; for(int i=0; i<varTextFields.size () && var==null; i++) { if(tf == varTextFields.get (i)) { var = (VcsConfigVariable) varVariables.get (i); } } if(var!=null){ var.setValue (tf.getText ().trim()); if (var.getName().equals("MODULE")) { // NOI18N /* String value = var.getValue(); if (value.length() > 0 && !value.endsWith(File.separator)) value = value.concat(File.separator); var.setValue(value); */ rootDirChanged(); } // enable fs to react on change in variables fileSystem.setVariables(fileSystem.getVariables()); //D.deb("variableChanged(): filesystemVariables = "+fileSystem.getVariables()); // NOI18N } else { E.deb ("Error setting variable:"+tf.getText ()); } } /** * Read configurations from disk. */ //------------------------------------------- private void updateConfigurations(){ D.deb("configRoot = "+fileSystem.getConfigRoot()); // NOI18N Vector configNames=VcsConfigVariable.readConfigurations(fileSystem.getConfigRootFO()); D.deb("configNames="+configNames); // NOI18N if( configCombo.getItemCount()>0 ){ // necessary on Linux configCombo.removeAllItems(); } configLabels = new Vector(5); configVariablesByLabel = new Hashtable(8); configAdvancedByLabel = new Hashtable(8); configNamesByLabel = new Hashtable(8); String selectedConfig=fileSystem.getConfig(); int newIndex=0; for(int i = 0; i < configNames.size(); i++){ String name=(String)configNames.elementAt(i); Properties props= VcsConfigVariable.readPredefinedProperties ( fileSystem.getConfigRootFO(), name); // NOI18N //( fileSystem.getConfigRoot()+File.separator+name+".properties"); // NOI18N String label=props.getProperty("label", g("CTL_No_label_configured")); configLabels.addElement(label); if( label.equals(selectedConfig) ){ newIndex=i; } configNamesByLabel.put(label,name); Vector variables=VcsConfigVariable.readVariables(props); configVariablesByLabel.put(label,variables); Object advanced=fileSystem.getVcsFactory (). getVcsAdvancedCustomizer ().readConfig (props); configAdvancedByLabel.put(label, advanced); //configCombo.addItem(label); } String[] sortedLabels = (String[]) configLabels.toArray(new String[0]); Arrays.sort(sortedLabels); configLabels = new Vector(Arrays.asList(sortedLabels)); for(int i = 0; i < configLabels.size(); i++) { String label = (String) configLabels.elementAt(i); if( label.equals(selectedConfig) ){ newIndex=i; } configCombo.addItem(label); } if (configCombo.getItemCount() > 0) configCombo.setSelectedIndex( newIndex ); promptForConfigComboChange = false; } //------------------------------------------- public void setObject(Object bean){ //D.deb("setObject("+bean+")"); // NOI18N fileSystem=(VcsFileSystem)bean; rootDirTextField.setText (VcsFileSystem.substractRootDir (fileSystem.getRootDirectory ().toString (), getModuleValue ())); refreshTextField.setText (""+fileSystem.getCustomRefreshTime ()); // NOI18N updateConfigurations(); initAdditionalComponents (); /* // find if this fs is in the repository boolean alreadyMounted = false; Enumeration en = TopManager.getDefault ().getRepository ().getFileSystems (); while (en.hasMoreElements ()) { if(fileSystem==en.nextElement ()) alreadyMounted = true; } System.out.println ("mounted:"+alreadyMounted); if(alreadyMounted) { String label = fileSystem.getConfig (); Object backupV = configVariablesByLabel.get (label); Object backupC = configAdvancedByLabel.get (label); // fake config in hashtables by values from fs configVariablesByLabel.put (label, fileSystem.getVariables ()); configAdvancedByLabel.put (label, fileSystem.getAdvancedConfig ()); oldIndex = -1; // let it read variables and commands configCombo.setSelectedItem (label); configVariablesByLabel.put (label, backupV); configAdvancedByLabel.put (label, backupC); } */ } /** * Search for MODULE variable and return its value */ private String getModuleValue() { Vector variables = fileSystem.getVariables(); for(int i = 0; i < variables.size(); i++) { VcsConfigVariable var = (VcsConfigVariable) variables.get(i); if (var.getName().equals("MODULE")) return var.getValue(); // NOI18N } return null; } private void rootDirChanged () { // root dir set by hand String selected= rootDirTextField.getText (); if( selected==null ){ //D.deb("no directory selected"); // NOI18N return ; } /* String module = getModuleValue(); String moduleDir = selected; if (module != null && module.length() > 0) moduleDir += File.separator + module; D.deb("rootDirChanged(): module = "+module+", selected = "+selected); // NOI18N File dir=new File(moduleDir); */ File root = new File(selected); /* if( !root.isDirectory() ){ E.err("not directory "+root); final String badDir = root.toString(); javax.swing.SwingUtilities.invokeLater(new Runnable () { public void run () { if (isRootNotSetDlg) { isRootNotSetDlg = false; TopManager.getDefault ().notify (new NotifyDescriptor.Message(MessageFormat.format (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.notDirectory"), new Object[] { badDir } ))); isRootNotSetDlg = true; } } }); return ; } */ try{ fileSystem.setRootDirectory(root); //rootDirTextField.setText(selected); } catch (PropertyVetoException veto){ fileSystem.debug(org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.canNotChangeWD")); //E.err(veto,"setRootDirectory() failed"); // NOI18N } catch (IOException e){ E.err(e,"setRootDirectory() failed"); final String badDir = root.toString(); javax.swing.SwingUtilities.invokeLater(new Runnable () { public void run () { if (isRootNotSetDlg) { isRootNotSetDlg = false; TopManager.getDefault ().notify (new NotifyDescriptor.Message(MessageFormat.format (org.openide.util.NbBundle.getBundle(VcsCustomizer.class).getString("VcsCustomizer.cannotSetDirectory"), new Object[] { badDir } ))); isRootNotSetDlg = true; } } }); } } private void refreshChanged () { try { int time = Integer.parseInt(refreshTextField.getText()); if (time < 0) throw new NumberFormatException(""+time); // NOI18N fileSystem.setCustomRefreshTime (time); E.deb("refresh time set to:" + time); } catch (NumberFormatException e) { final String msg = e.getMessage(); E.deb(e.getMessage()); refreshTextField.setText (""+fileSystem.getCustomRefreshTime ()); // NOI18N javax.swing.SwingUtilities.invokeLater(new Runnable () { public void run () { TopManager.getDefault ().notify (new NotifyDescriptor.Message("'"+msg+"': Non-negative integer value is expected.")); } }); } } //------------------------------ private class BrowseLocalFile implements java.awt.event.ActionListener { private JTextField tf; public BrowseLocalFile(JTextField tf) { this.tf = tf; } public void actionPerformed (java.awt.event.ActionEvent evt) { ChooseFileDialog chooseFile=new ChooseFileDialog(new JFrame(), new File(tf.getText ()), false); MiscStuff.centerWindow (chooseFile); chooseFile.show(); String selected=chooseFile.getSelectedFile(); if( selected==null ){ //D.deb("no directory selected"); // NOI18N return ; } tf.setText(selected); variableChanged(new java.awt.event.ActionEvent(tf, 0, "")); // NOI18N } } //------------------------------ private class BrowseLocalDir implements java.awt.event.ActionListener { private JTextField tf; public BrowseLocalDir(JTextField tf) { this.tf = tf; } public void actionPerformed (java.awt.event.ActionEvent evt) { ChooseDirDialog chooseDir = new ChooseDirDialog(new JFrame(), new File(tf.getText ())); MiscStuff.centerWindow (chooseDir); chooseDir.show(); String selected=chooseDir.getSelectedDir(); if( selected==null ){ //D.deb("no directory selected"); // NOI18N return ; } tf.setText(selected); variableChanged(new java.awt.event.ActionEvent(tf, 0, "")); // NOI18N } } private class RunCustomSelector implements java.awt.event.ActionListener { private JTextField tf; private VcsConfigVariable selector; public RunCustomSelector(JTextField tf, VcsConfigVariable selector) { this.tf = tf; this.selector = selector; } public void actionPerformed (java.awt.event.ActionEvent evt) { OutputContainer container = new OutputContainer(g("MSG_VariableSelector")); final ExecuteSelector es = new ExecuteSelector(fileSystem, selector.getCustomSelector(), selector.getName(), fileSystem.getVariablesAsHashtable()); es.setErrorNoRegexListener(container); es.setOutputNoRegexListener(container); es.setErrorContainer(container); new Thread ("VCS-CustomSelector") { public void run() { es.start(); try { es.join(); } catch (InterruptedException e) { return; } String selection = es.getSelection(); if (selection != null && selection.length() > 0) { tf.setText(selection); variableChanged(new java.awt.event.ActionEvent(tf, 0, "")); // NOI18N //rootDirChanged(false); } } }.start(); } } //------------------------------------------- String g(String s) { return NbBundle.getBundle ("org.netbeans.modules.vcs.cmdline.Bundle").getString (s); } String g(String s, Object obj) { return MessageFormat.format (g(s), new Object[] { obj }); } String g(String s, Object obj1, Object obj2) { return MessageFormat.format (g(s), new Object[] { obj1, obj2 }); } String g(String s, Object obj1, Object obj2, Object obj3) { return MessageFormat.format (g(s), new Object[] { obj1, obj2, obj3 }); } } /* * <<Log>> * 16 Gandalf-post-FCS1.12.1.2 4/5/00 Martin Entlicher Enter removed from * keymaps of textfields * 15 Gandalf-post-FCS1.12.1.1 3/30/00 Martin Entlicher Localization * 14 Gandalf-post-FCS1.12.1.0 3/23/00 Martin Entlicher Configuration is deleted * via filesystem on delete action, fix of long width of advanced editor, * support for variable selector, the order of configuration files is set * by sort by labels. * 13 Gandalf 1.12 3/8/00 Martin Entlicher VCS properties read from * filesystem * 12 Gandalf 1.11 2/11/00 Martin Entlicher Different argument to * setRootDirectory * 11 Gandalf 1.10 2/10/00 Martin Entlicher Does not check the * existence of working directory. * 10 Gandalf 1.9 2/9/00 Martin Entlicher Fix of width of Advanced * Dialog. * 9 Gandalf 1.8 1/27/00 Martin Entlicher NOI18N * 8 Gandalf 1.7 1/26/00 Martin Entlicher Check whether the module * directory exists * 7 Gandalf 1.6 1/3/00 Martin Entlicher * 6 Gandalf 1.5 12/16/99 Martin Entlicher * 5 Gandalf 1.4 12/15/99 Martin Entlicher Refresh time: check for * correct input * 4 Gandalf 1.3 12/8/99 Martin Entlicher * 3 Gandalf 1.2 12/8/99 Martin Entlicher Added browse buttons. * 2 Gandalf 1.1 11/27/99 Patrik Knakal * 1 Gandalf 1.0 11/24/99 Martin Entlicher * $ */